package Dao;

import bean.*;

import java.util.List;

public class medicineDao extends  BaseDao{
    public List<medicine> queryMedicines() throws Exception {
        String sql = "SELECT * FROM medicine";
        return queryForList(medicine.class,sql);
    }

//    上述SQL语句创建一个名为medicine的药品表，其中id字段为自增主键，name为药品名称，
//    code为药品编码，category为药品分类，specification为药品规格，
//    producer为药品产地，price为药品价格，quantity为库存数量。药品表中的每一行代表一个药品。

    public medicine queryMedicineByName(String name) {
        String sql = "SELECT mid,name,code,category,specification,producer,price,quantity,efficacy FROM medicine WHERE name = ?";
        try {
            return queryForOne(medicine.class,sql,name);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public List<medicine> queryMedicineByCategory(String category) {
        String sql = "SELECT mid,name,code,category,specification,producer,price,quantity,efficacy FROM medicine WHERE category = ?";
        try {
            return queryForList(medicine.class,sql,category);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    public medicine queryMedicineById(String id) {
        String sql = "SELECT mid,name,code,category,specification,producer,price,quantity,efficacy FROM medicine WHERE mid = ?";
        try {
            return queryForOne(medicine.class,sql,id);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
